home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 242 / Issue 242 - April 2008 - DPCS0408DVD.ISO / Software Money Savers / VirtualDub / Source / VirtualDub-1.7.7-src.7z / src / system / source / a64_thunk.asm < prev    next >
Encoding:
Assembly Source File  |  2007-09-02  |  1.1 KB  |  59 lines

  1.         .code
  2.         
  3. VDMethodToFunctionThunk64    proc public frame
  4.         ;prolog
  5.         db            48h                ;emit REX prefix -- first instruction must be two bytes for hot patching
  6.         push        rbp
  7.         .pushreg    rbp
  8.         
  9.         mov            rbp, rsp        ;create stack pointer
  10.         .setframe    rbp, 0
  11.         
  12.         mov            [rbp+16], rcx    ;save arg1
  13.         .savereg    rcx, 0
  14.         
  15.         mov            [rbp+24], rdx    ;save arg2
  16.         .savereg    rcx, 8
  17.  
  18.         mov            [rbp+32], r8    ;save arg3
  19.         .savereg    rcx, 16
  20.  
  21.         mov            [rbp+40], r9    ;save arg4
  22.         .savereg    rcx, 24
  23.         
  24.         .endprolog
  25.                 
  26.         ;re-copy arguments 4 and up
  27.         mov            ecx, [rax+24]
  28.         or            ecx, ecx
  29.         jz            argsdone
  30.         lea            rdx, [rcx+48-8]
  31. argsloop:
  32.         push        qword ptr [rsp+rdx]
  33.         sub            ecx, 8
  34.         jnz            argsloop
  35. argsdone:
  36.         
  37.         ;load 'this' pointer
  38.         mov            rcx, [rax+16]
  39.         
  40.         ;reload arguments 1-3
  41.         mov            rdx, [rbp+16]
  42.         mov            r8, [rbp+24]
  43.         mov            r9, [rbp+32]
  44.         
  45.         ;reserve argument 1-4 space on stack
  46.         sub            rsp, 32
  47.         
  48.         ;call function
  49.         call        qword ptr [rax+8]
  50.         
  51.         ;epilog
  52.         lea            rsp, [rbp]        ;pop off stack frame and any additional arg space
  53.         pop            rbp                ;restore base pointer
  54.         ret                            ;all done
  55.  
  56. VDMethodToFunctionThunk64    endp
  57.  
  58.         end
  59.